/*
package com.ks.core.util;


import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosAlert;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;

import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

*/
/**
 * 极光推送工具类
 * Created 2019/1/17.
 *//*

public class JPushUtil {
    public static String appkey = "a27f7e56324802336284fa96";
    public static String mastersecret = "886925ab7d900042f00f9df4";

    //方法
    private static void readProperty() {
        Properties prop = new Properties();
        InputStream in = Object.class.getResourceAsStream("/JPushKey.properties");
        try {
            prop.load(in);
            appkey = prop.getProperty("appkey").trim();
            mastersecret = prop.getProperty("mastersecret").trim();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //极光推送>>Android
    //Map<String, String> parm是我自己传过来的参数,可以自定义参数
    public void jpushAndroid(Map<String, String> parm, int type) {
        Audience audience = null;
        if (type == 0) {
            audience = Audience.all();
        } else {
            audience = Audience.alias(parm.get("id"));
        }
        //创建JPushClient(极光推送的实例)
        JPushClient jpushClient = new JPushClient(appkey, mastersecret);
        //推送的关键,构造一个payload
        PushPayload payload = PushPayload.newBuilder()
                .setPlatform(Platform.android())//指定android平台的用户
                .setAudience(audience)//你项目中用户
//                .setAudience(Audience.alias(parm.get("alias")))//设置别名发送,单发，点对点方式
//                .setAudience(Audience.tag("tag1"))//设置按标签发送，相当于群发
                .setNotification(Notification.android(parm.get("msg"), parm.get("title"), parm))  //发送内容
                .setOptions(Options.newBuilder().setApnsProduction(true).setTimeToLive(7200).build())
                // apnProduction指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式) 不用设置也没关系
                // TimeToLive 两个小时的缓存时间
                .setMessage(Message.content(parm.get("msg")))//自定义信息
                .build();

        try {
            PushResult pu = jpushClient.sendPush(payload);
            System.out.println(pu.toString());
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        }
    }

    //极光推送>>ios
    //Map<String, String> parm是我自己传过来的参数,可以自定义参数
    public void jpushIOS(Map<String, String> parm, int type) {
        Audience audience = null;
        if (type == 0) {
            audience = Audience.all();
        } else {
            audience = Audience.alias(parm.get("id"));
        }
        //创建JPushClient
        JPushClient jpushClient = new JPushClient(appkey, mastersecret);
        PushPayload payload = PushPayload.newBuilder()
                .setPlatform(Platform.ios())//ios平台的用户
                .setAudience(audience)//项目用户
                .setNotification(Notification.newBuilder()
                        .addPlatformNotification(IosNotification.newBuilder()
                                .setAlert(parm.get("msg"))
                                .setBadge(+1)
                                .setSound("happy")//这里是设置提示音(更多可以去官网看看)
                                .addExtras(parm)
                                .build())
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(false).build())
                .setMessage(Message.newBuilder().setMsgContent(parm.get("msg")).addExtras(parm).build())//自定义信息
                .build();

        try {
            PushResult pu = jpushClient.sendPush(payload);
            System.out.println(pu.toString());
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        }
    }


    //极光推送>>All所有平台
    public static void jpushAll(Map<String, String> parm, int type,String prefix) {
        Audience audience = null;
        if (type == 0) {
            audience = Audience.all();
        } else {
            audience = Audience.alias(parm.get("id"));
        }
        //创建JPushClient
        readProperty();
        JPushClient jpushClient = new JPushClient(mastersecret, appkey);
        //创建option
        if (prefix.equals("ys")){
            IosAlert build = IosAlert.newBuilder().setTitleAndBody(parm.get("title"), "", parm.get("msg")).build();
            PushPayload payload = PushPayload.newBuilder()
                    .setPlatform(Platform.all())  //所有平台的用户
                    .setAudience(audience)//用户
                    .setNotification(Notification.newBuilder()
                            .addPlatformNotification(IosNotification.newBuilder()//发送ios
                                    .setAlert(build) //消息体
                                    .setBadge(+1)
                                    .setSound("happy") //ios提示音
                                    .addExtras(parm) //附加参数
                                    .build())
                            .addPlatformNotification(AndroidNotification.newBuilder()
                                    .setTitle(parm.get("title"))//发送android
                                    .addExtras(parm) //附加参数
                                    .setAlert(parm.get("msg")) //消息体
                                    .build())
                            .build())
                    .setOptions(Options.newBuilder().setApnsProduction(false).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
                    .setMessage(Message.newBuilder().setMsgContent(parm.get("msg")).addExtras(parm).build())//自定义信息
                    .build();
            try {
                PushResult pu = jpushClient.sendPush(payload);
                System.out.println(pu.toString());
            } catch (APIConnectionException e) {
                e.printStackTrace();
            } catch (APIRequestException e) {
                e.printStackTrace();
            }
        }else {
            IosAlert build = IosAlert.newBuilder().setTitleAndBody(parm.get("title"), "", parm.get("msg")).build();
            PushPayload payload = PushPayload.newBuilder()
                    .setPlatform(Platform.all())  //所有平台的用户
                    .setAudience(audience)//用户
                    .setNotification(Notification.newBuilder()
                            .addPlatformNotification(IosNotification.newBuilder()//发送ios
                                    .setAlert(build) //消息体
                                    .setBadge(+1)
                                    .setSound("happy") //ios提示音
                                    .addExtras(parm) //附加参数
                                    .build())
                            .addPlatformNotification(AndroidNotification.newBuilder()
                                    .setTitle(parm.get("title"))//发送android
                                    .addExtras(parm) //附加参数
                                    .setAlert(parm.get("msg")) //消息体
                                    .build())
                            .build())
                    .setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
                    .setMessage(Message.newBuilder().setMsgContent(parm.get("msg")).addExtras(parm).build())//自定义信息
                    .build();
            try {
                PushResult pu = jpushClient.sendPush(payload);
                System.out.println(pu.toString());
            } catch (APIConnectionException e) {
                e.printStackTrace();
            } catch (APIRequestException e) {
                e.printStackTrace();
            }
        }


    }
}
*/
